Skip to content

gh-139103: Defer reference count mutable class attributes - #155876

Open
johng wants to merge 3 commits into
python:mainfrom
johng:worktree-ft-scaling-139103
Open

johng wants to merge 3 commits into
python:mainfrom
johng:worktree-ft-scaling-139103

Conversation

@johng

@johng johng commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Mutable class attributes would not scale with more threads, adding defered reference counting to the non owning threads reduces the churn.

./python_main.exe Tools/ftscalingbench/ftscalingbench.py class_attribute Running benchmarks with 18 threads
class_attribute 6.3x slower

./python.exe Tools/ftscalingbench/ftscalingbench.py class_attribute Running benchmarks with 18 threads
class_attribute 8.0x faster

Mutable class attributes would not scale with more
threads, adding defered reference counting to resolve it.

./python_main.exe Tools/ftscalingbench/ftscalingbench.py class_attribute
Running benchmarks with 18 threads
class_attribute            6.3x slower

./python.exe Tools/ftscalingbench/ftscalingbench.py class_attribute
Running benchmarks with 18 threads
class_attribute            8.0x faster
@johng
johng marked this pull request as ready for review August 15, 2026 23:33
@johng

johng commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

Happy to create a new issue for this if the linked one is not close enough

Add a free-threading test that reads a class attribute holding an
instance of a different class from a non-owning thread and checks that
the failed LOAD_ATTR_CLASS specialization attempt enables deferred
reference counting on the value, and that the value is still reclaimed
by the GC once unreachable.
@johng

johng commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

CC @kumaraditya303 @colesbury thanks!

@johng

johng commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

Deferred reference counting was added in the branch where mutable class attributes hit, but maybe this can be done at the top of specialize_class_load_attr if it makes sense for all branches instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant